<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>添加收件人信息</title>
		<link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
		<script type="text/javascript" src="/webapp/js/common/cities.js"></script>
        <script type="text/javascript" charset="utf-8" src="/webapp/js/lib/ueditor.config.js"></script>
        <script type="text/javascript" charset="utf-8" src="/webapp/js/lib/ueditor.all.min.js"> </script>
        <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
        <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
        <script type="text/javascript" charset="utf-8" src="/webapp/js/lib/lang/zh-cn/zh-cn.js"></script>

	</head>
	<body>

		<div class="easyui-container-fluid">
            <div class="easyui-panel" style="border: none;">
                <div class="nav" id="nav"></div>
                <div class="easyui-panel" style="border:none;">
                	<form id="ff" name="ff">
                        <div style="margin-bottom:20px;">
                            <label class="item-label" >企业名称：</label>
                            <select class="easyui-combobox" id="company"  required="required" style="width:174px;" name="company">
                            </select>
                            <label class="item-label" >负责人姓名：</label>
                            <select class="easyui-combobox" id="principal"  required="required" style="width:174px;" name="principalCode" data-options="multiple:true">
                            </select>
                            <label class="item-label" >报告模式：</label>
                            <select  name="recordMode" class="easyui-combobox" id="recoedMode"data-options="panelHeight:'auto'" style="width:100px;">
                                <option value="OFFLINE">线下</option>
                                <option value="ONLINE">线上</option>
                            </select>
                            <label class="item-label">报告类型：</label>
                            <select  name="reportType" class="easyui-combobox"id="reportType" data-options="panelHeight:'auto'" style="width:100px;">
                                <option value="MONTH">月度报</option>
                                <option value="WEEK">周度报</option>
                                <option value="QUARTER">季度报</option>
                                <option value="HYEAR">半年报</option>
                            </select>

                        </div>
                        <div style="margin-bottom:20px;">
                            <label class="item-label" >邮件主题：</label>
                            <input type="text" class="easyui-textbox" name="title" style="width:200px;" />
                            <label class="item-label"><span class="item-required">*</span>报告名称：</label>
                            <input name="proportion" class="easyui-tagbox proportion" style="width:602px;min-height:80px;"required="required" data-options="multiline:true"/>

                        </div>
                        <div style="margin-bottom:20px;">
                            <label class="item-label" >邮件内容：</label>
                            <div  style="margin-bottom:20px;margin-left:100px;"><script id="editor"  name="content" type="text/plain" style="width:900px;height:300px;"></script></div>
                        </div>
                        <div style="margin-bottom:20px;margin-left:100px;">
                            <a href="javascript:void(0);" class="easyui-linkbutton c8" style="width:80px" onclick="submitForm()">保存</a>
                            <a href="javascript:void(0);" class="easyui-linkbutton" style="width:80px;" onclick="clearForm()">取消</a>
                        </div>
                	</form>
                </div>
            </div>
            </div>
		</div>
	</body>

</html>

<script type="text/javascript">
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');
    var id = getQueryParameter("id");
    $(function () {
        setNav();
        if (id) {
            $.when(initCompanyS("company")).done(function () {
                initFormData()
            });
        }else{
           initCompanyS("company", "principal")
        }
        // initFormData()
    });
    function initFormData() {
        if (id) {
            $.ajax({
                url: config.url + "/emailReceiving/" + id,
                type: "GET",
                dataType: "json",
                data: JSON.stringify(id),
                contentType: "application/json;charset=UTF-8",
                xhrFields: {withCredentials: true},
                success: function (data) {
                    //填充表单
                    if (data) {
                        $.when(initPrincipalS("principal", data.company)).done(function () {
                            var filmDesc = data.content;
                            ue.execCommand('insertHtml', filmDesc);
                            $("#ff").form("load", changeProperty2String(data));
                            //多选赋值

                            // $('#principal').combobox('setValues', data.principalName+",");
                        });
                    }
                },
                error: function () {
                }
            });

        }

    }

    function submitForm() {
        $("#ff").form("submit", {
            onSubmit: function () {
                var valid = $(this).form('enableValidation').form('validate');
                if (valid) {
                    var mall = getFormData(document.getElementById("ff"));
                    var method = "POST";
                    if (id) {
                        method = "PATCH";
                        mall.id = id;
                    }
                    var proportion = $(".proportion").combobox('getValues');
                    mall.proportion = proportion;
                    var principal = $("#principal").combobox('getValues');
                    mall.principalCode = principal;
                    // var arr = [];
                    // arr.push("使用editor.getContent()方法可以获得编辑器的内容");
                    // arr.push("内容为：");
                    // arr.push(UE.getEditor('editor').getContent());
                    // alert(arr.join("\n"));
                    mall.content = UE.getEditor('editor').getContent();
                    // console.log(mall);
                    $.ajax({
                        url: config.url + "/emailReceiving",
                        type: method,
                        data: JSON.stringify(mall),
                        dataType: 'json',
                        contentType: 'application/json;charset=UTF-8',
                        beforeSend: function () {
                            $.messager.progress({
                                title: "请稍等",
                                interval: 50,
                                text: "操作进行中..."
                            });
                        },
                        complete: function () {
                            $.messager.progress("close");
                        },
                        xhrFields: {withCredentials: true},
                        success: function (data) {
                            $.messager.alert("提示", "操作成功", "info", function () {
                                window.parent.closeCurrentTab(true);
                            });
                        },
                        error: function (XMLHttpRequest, textStatus, thrown) {
                            $.messager.alert("提示", "操作失败", "error");
                        }
                    });
                    return false;
                }
                return false;

            }
        });
    }

    function clearForm() {
        window.parent.closeCurrentTab();
    }


    function getContent() {
        var arr = [];
        arr.push("使用editor.getContent()方法可以获得编辑器的内容");
        arr.push("内容为：");
        arr.push(UE.getEditor('editor').getContent());
        alert(arr.join("\n"));
    }


</script>